<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        components: {
            SelectImage: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImage()),
            SelectDataGoods: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataGoods()),
        },
        data() {
            return {
                appWindow: window,
                form: {
                    // 一级分销商佣金比例
                    agent_commission_1: 0,
                    // 二级分销商佣金比例
                    agent_commission_2: 0,
                    // 三级分销商佣金比例
                    agent_commission_3: 0,

                    // 累计充值金额
                    all_recharge_money: 0,
                    // 下线分销商人数
                    child_agent_count: 0,
                    // 一级下线分销商
                    child_agent_count_1: 0,
                    // 下线人数
                    child_count: 0,
                    // 一级下线人数
                    child_count_1: 0,
                    // 一级佣金比例
                    commission_1: 0,
                    // 二级佣金比例
                    commission_2: 0,
                    // 三级佣金比例
                    commission_3: 0,
                    // 指定商品id 
                    goods_ids: [],
                    // 等级名称
                    name: "",
                    // 分销订单总数
                    order_count: 0,
                    // 一级分销订单总数
                    order_count_1: 0,
                    // 分销订单总额
                    order_money: 0,
                    // 一级分销订单总额
                    order_money_1: 0,
                    // 单笔充值金额
                    recharge_money: 0,
                    // 自购订单总数
                    self_order_count: 0,
                    // 自购订单总额
                    self_order_money: 0,
                    // 升级方式
                    upgrade_type: 1,
                    // 已提现佣金金额
                    withdraw_money: 0,

                    // 等级权重
                    level: null,
                    distribution_level_weight_id: null,
                    // 布尔值，说明这个是不是默认等级
                    default: 0,
                    extra: [],

                },
                // 页面接口地址
                apiUrl: {
                    create: "plugin/distribution/backend/levels/store",
                    update: "plugin/distribution/backend/levels/store",
                    detail: "plugin/distribution/backend/levels/edit",
                },

                conditionList: [
                    "下线分销商人数", 
                    "一级下线分销商", 
                    "下线人数", 
                    "一级下线人数", 
                    "分销订单总数", 
                    "一级分销订单总数", 
                    "分销订单总额", 
                    "一级分销订单总额",
                    "自购订单总数",
                    "自购订单总额", 
                    "已提现佣金金额",
                    "单笔充值金额",
                    "购买指定商品",
                    "累计充值金额", 
                ],

                // 等级权重数据
                levelList: [],

                // 
                activelist: [],
            };
        },
        methods: {
            // 获取等级权重
            async getLevel() {
                let res = await this.$vFN.Http.post({
                    url: "plugin/distribution/backend/levels/create",
                }, window);
                // console.log(res);
                this.levelList = res.data.level_status;
            },
            // 选择等级权重
            addLevel(_value) {
                this.form.level = _value;
                this.form.distribution_level_weight_id = _value;
            },

            // form 提交添加/修改 的参数扩展方法
            mixinEdit_editFormSubmitExtend(data_) {
                
                return data_;
            },
            // 编辑修改的参数扩展方法
            mixinEdit_editDataExtend(data_) {
                // 添加
                if (this.mixinEdit_editType == "add") {
                    this.getLevel();
                }
                // 修改
                else if (this.mixinEdit_editType == "update") {
                    this.levelList = data_.level_status;
                    data_ = data_.data
                    // data_.extra = this.activelist;

                }
                // 复制
                else if (this.mixinEdit_editType == "copy") {
                    
                }

                return data_;
            },
            
            select(item, index) {
                if(!this.form.extra.includes(index)) {
                    this.form.extra.push(index);
                }
            },

            del(_id, name) {
                let arr = []
                this.form.extra.forEach(item => {
                    if(item != _id) {
                        arr.push(item)
                    }
                })
                this.form.extra = arr;
                // 删除后让值归0
                switch(name) {
                    case 'child_agent_count':
                        this.form.child_agent_count = 0;
                        break;
                    case 'child_agent_count_1':
                        this.form.child_agent_count_1 = 0;
                        break;
                    case 'child_count':
                        this.form.child_count = 0;
                        break;
                    case 'child_count_1':
                        this.form.child_count_1 = 0;
                        break;
                    case 'order_count':
                        this.form.order_count = 0;
                        break;
                    case 'order_count_1':
                        this.form.order_count_1 = 0;
                        break;
                    case 'order_money':
                        this.form.order_money = 0;
                        break;
                    case 'order_money_1':
                        this.form.order_money_1 = 0;
                        break;
                    case 'self_order_count':
                        this.form.self_order_count = 0;
                        break;
                    case 'self_order_money':
                        this.form.self_order_money = 0;
                        break;
                    case 'withdraw_money':
                        this.form.withdraw_money = 0;
                        break;
                    case 'recharge_money':
                        this.form.recharge_money = 0;
                        break;
                    case 'goods_ids':
                        this.form.goods_ids = [];
                        break;
                    case 'all_recharge_money':
                        this.form.all_recharge_money = 0;
                        break;
                }
            },

            // 初始化
            async init() {
                // 初始化数据
                await this.mixinEdit_editBoxInit({
                    model: "form",
                    id: this.id,
                });
            },


        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>